Polygon2

data class Polygon2(val vertices: List<Vec2>, val precision: DoubleEquivalence = DEFAULT_DOUBLE_EQUIVALENCE) : Polygon<Vec2> (source)

Represents a polygon in 2D space defined by a list of vertices.

The polygon is defined by its vertices in order (either clockwise or counterclockwise). The last vertex is implicitly connected to the first vertex to close the polygon.

Constructors

Link copied to clipboard
constructor(vertices: List<Vec2>, precision: DoubleEquivalence = DEFAULT_DOUBLE_EQUIVALENCE)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

Returns the edges of the polygon as a list of segments.

Link copied to clipboard

The precision used for geometric computations, defaulting to DEFAULT_DOUBLE_EQUIVALENCE.

Link copied to clipboard
open val vertexCount: Int

Returns the number of vertices in the polygon.

Link copied to clipboard
open override val vertices: List<Vec2>

The list of vertices defining the polygon, must have at least 3 vertices.

Functions

Link copied to clipboard
open override fun area(): Double

Computes the area of the polygon.

Link copied to clipboard

Computes the axis-aligned bounding box of the polygon.

Link copied to clipboard
open override fun centroid(): Vec2

Computes the centroid (geometric center) of the polygon.

Link copied to clipboard
open override fun contains(point: Vec2): Boolean

Checks if a point is inside the polygon.

Link copied to clipboard
open override fun dimensions(): Int

Returns the number of dimensions of the spatial object.

Link copied to clipboard
open override fun isConvex(): Boolean

Checks if the polygon is convex.

Link copied to clipboard
open override fun isFinite(): Boolean

Returns true if all values in the spatial are finite.

Link copied to clipboard
open override fun isInfinite(): Boolean

Returns true if any value in the spatial is infinite.

Link copied to clipboard
open override fun isNaN(): Boolean

Returns true if any value in the spatial is NaN (Not a Number).

Link copied to clipboard
open override fun isSimple(): Boolean

Checks if the polygon is simple (non-self-intersecting).

Link copied to clipboard

Determines the orientation of the polygon based on the sign of its area.

Link copied to clipboard
open override fun perimeter(): Double

Computes the perimeter of the polygon.

Link copied to clipboard
open override fun reverse(): Polygon2

Reverses the order of vertices, effectively reversing the orientation of the polygon.

Link copied to clipboard
open override fun scale(factor: Double, center: Vec2): Polygon2

Scales the polygon by a given factor around a center point.

Link copied to clipboard
open override fun signedArea(): Double

Computes the signed area of the polygon.

Link copied to clipboard
open override fun transform(transformer: Transformer<Vec2>): Polygon2

Transforms the polygon by applying a transformation to all vertices.

Link copied to clipboard
open override fun translate(offset: Vec2): Polygon2

Translates the polygon by a given offset vector.